﻿using AutoMapper;
using BaseData.API.Write.Applications.Commands;
using BaseData.Domain;
using BaseData.ErrorCode;
using BaseData.Infrastructure.Interfaces;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace BaseData.API.Write.Applications.CommandHandlers
{
    /// <summary>
    /// 添加权限
    /// </summary>
    public class DelPermissionCommandHandler : IRequestHandler<DelPermissionCommand, ApiResult<int>>
    {
        private readonly IBaseRepository<Permission> perRep;
        private readonly IMapper mapper;

        public DelPermissionCommandHandler(IBaseRepository<Permission> perRep,
            IMapper mapper)
        {
            this.perRep = perRep;
            this.mapper = mapper;
        }
        public async Task<ApiResult<int>> Handle(DelPermissionCommand request, CancellationToken cancellationToken)
        {
          

            ApiResult<int> result = new ApiResult<int>();
            result.Code=ApiEnum.删除成功;
            result.Message = ApiEnum.删除成功.ToString();

           var per=await perRep.GetById(request.PermissionId);
            per.IsDel=true;
            await perRep.UpdateAsync(per);
            result.Data = 1;

            return await Task.FromResult(result);
        }
    }
}
